package org.offsync.util

import org.offsync.rich._

class Slot[T](private var bucket: Option[T] = None) {
  private val lock = new Object
  
  def get: T = lock.synchronized {
    while (bucket.isEmpty) {
      lock.wait()
    }
    
    return bucket.get
  }
  
  def get(deadline: Time): T = lock.synchronized {
    while (bucket == None) {
      deadline.enforceDeadline()
      lock.wait(deadline)
    }
    
    return bucket.get
  }
  
  def set(value: T): Unit = lock.synchronized {
    bucket = Some(value)
    lock.notifyAll()
  }
}
